import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue'),
    beforeEnter: (to, from, next) => {
      if (localStorage.getItem('tokenB')) {
        next('/')
      } else {
        next()
      }
    }
  },
  {
    path: '/',
    name: '',
    component: () => import('@/views/Index.vue'),
    redirect: 'home',
    beforeEnter: (to, from, next) => {
      if (localStorage.getItem('tokenB')) {
        next()
      } else {
        next('/login')
      }
    },
    children: [
      {
        path: 'home',
        meta: {
          title: '首页'
        },
        component: () => import('@/views/home/home.vue')
      },
      // ...user
    ]

  },
  {
    path: '/about',
    name: 'about',
    component: () => import('@/views/AboutView.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
